home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 05 / 6 / DISK0564.ZIP / SOURCE.ARC / B.ARC / COM.C < prev    next >
C/C++ Source or Header  |  1986-04-09  |  2KB  |  100 lines

  1. /* routines to access the communications port using IBM    BIOS interrupts    */
  2. /* for Aztec C86 vers. 3.20e */
  3. /* by Jon Dart,    Feb. 1986 */
  4.  
  5. #include "truth.h"
  6.  
  7. extern bios();
  8.  
  9. #define    bios_int 20
  10. #define    DATAREADY 0x0100
  11.  
  12. struct regstruc    {
  13.     unsigned int ax,bx,cx,dx;
  14. };
  15.  
  16. static struct regstruc regs;
  17.  
  18. cominit(baud,parity,stop,wordlen)
  19. /* initializes rs232 port */
  20. /* returns rs-232 status, -1 if    error */
  21. unsigned int baud,stop,wordlen;    char parity;
  22. {
  23.     unsigned int b,p,wl;
  24.  
  25.     switch(baud) {
  26.     case 110: b = 0; break;
  27.     case 150: b = 1; break;
  28.     case 300: b = 2; break;
  29.     case 600: b = 3; break;
  30.     case 1200: b= 4; break;
  31.     case 2400: b= 5; break;
  32.     case 4800: b= 6; break;
  33.     case 9600: b= 7; break;
  34.     default:
  35.         return(-1);
  36.     }
  37.     switch (wordlen) {
  38.     case 5:    wl = 0;    break;
  39.     case 6:    wl = 1;    break;
  40.     case 7:    wl = 2;    break;
  41.     case 8:    wl = 3;    break;
  42.     default: return(-1);
  43.     }
  44.     switch (parity) {
  45.     case 'N': p=0; break;
  46.     case 'E': p=3; break;
  47.     case 'O': p=1; break;
  48.     default: return(-1);
  49.     }
  50.     regs.dx = 0;
  51.     regs.ax = (b<<5) | (p<<3) |    ((stop-1)<<2) |    wl;
  52.     bios(bios_int,0,®s);
  53.     return(regs.ax);
  54. }
  55.  
  56. comstatus()
  57. /* returns rs-232 status word */
  58. {
  59.     regs.dx = 0;
  60.     bios(bios_int,3,®s);
  61.     return(regs.ax);
  62. }
  63.  
  64. transmit(c)
  65. /* send    c out the serial port */
  66. /* returns status = bit    15 set if timeout */
  67. char c;
  68. {
  69.     unsigned int status;
  70.     while ((status = comstatus() & 0xA000)==0) ; /* wait for THR empty
  71.                             or timeout*/
  72.     if ((status    & 0x2000)!=0) {
  73.     regs.ax= (int) c;
  74.     regs.dx= 0;
  75.     bios(bios_int,1,®s);
  76.     return(regs.ax>>8);
  77.     }
  78.     else /* timeout */
  79.     return(status);
  80. }
  81.  
  82. receive(c)
  83. /* get c from the serial port */
  84. /* returns status = TRUE if success */
  85. char *c;
  86. {
  87.     if (comstatus() & DATAREADY) {
  88.     regs.dx    = 0;
  89.     bios(bios_int,2,®s);
  90.     *c = (regs.ax &    0xFF);
  91.     if (regs.ax>>8)
  92.         return(FALSE);
  93.     else
  94.         return(TRUE);
  95.     }
  96.     else
  97.     return(FALSE);
  98. }
  99.  
  100.